# coding: utf-8
from datetime import datetime
from sqlalchemy import Column, String, Integer, DateTime, ForeignKey
from app.extensions import db

"""
系统接入配置表
"""
class SystemAccessConfig(db.Model):
    __tablename__ = 'sjml_system_config'

    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键ID')
    department = Column(String(100), nullable=False, comment='所属部门')
    system_name = Column(String(200), nullable=False, comment='系统全称')
    system_alias = Column(String(200), nullable=False, comment='系统简称')
    system_desc = Column(String(500), comment='系统介绍')
    major = Column(String(100), comment='所属专业')
    network = Column(String(100), comment='所属网络')
    deploy_mode = Column(String(50), comment='部署方式')
    promotion_type = Column(String(50), comment='推广类型')
    address = Column(String(255), comment='登陆地址')
    contact = Column(String(100), comment='联系方式')
    username = Column(String(100), comment='用户名')
    password = Column(String(100), comment='密码')
    leader = Column(String(100), comment='系统负责人')
    create_time = Column(DateTime, default=datetime.now, nullable=False, comment='创建时间')

    def to_dict(self):
        return {
            'id': self.id,
            'department': self.department,
            'system_name': self.system_name,
            'system_alias': self.system_alias,
            'system_desc': self.system_desc,
            'major': self.major,
            'network': self.network,
            'deploy_mode': self.deploy_mode,
            'promotion_type': self.promotion_type,
            'address': self.address,
            'contact': self.contact,
            'username': self.username,
            'password': self.password,
            'leader': self.leader,
            'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S') if self.create_time else None
        }
